package cn.jaye.fabric.common.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;


@WebFilter
public class HttpServletFilter implements Filter {

    private static final long serialVersionUID = 1L;

    public HttpServletFilter() {
        super();
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        ServletRequest requestWrapper = null;
        if (request instanceof HttpServletRequest) {
//            HttpServletRequest req = (HttpServletRequest) request;
//            request.getRequestDispatcher("/login")
//            if ("POST".equalsIgnoreCase(req.getMethod())) {
//                try {
//                    requestWrapper = new MyHttpServletRequestWrapper(req);
//                } catch (Exception e) {
//                    if (e instanceof ServiceException) {
//                        response.setContentType("application/json");
//                        response.setCharacterEncoding("UTF-8");
//                        String write = ResultUtil.error(ExceptionEnum.INVALID_PARAMETER);
//                        response.getWriter().write(write);
//                        return;
//                    }
//                    throw e;
//                }
//            }
        }
        chain.doFilter(request, response);
//        if (null == requestWrapper) {
//            chain.doFilter(request, response);
//        } else {
//            chain.doFilter(requestWrapper, response);
//        }

    }

    @Override
    public void destroy() {

    }

}

